home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / RxSlides / blit.c < prev    next >
C/C++ Source or Header  |  1990-03-08  |  4KB  |  130 lines

  1. /* :bk=0 */
  2.  
  3. /***************************************************************************
  4.  *
  5.  *                            BLIT.C
  6.  *
  7.  ***************************************************************************/
  8.  
  9. #include "exec/types.h"
  10. #include "exec/memory.h"
  11. #include "graphics/copper.h"
  12. #include "graphics/gfx.h"
  13. #include "graphics/view.h"
  14. #include "graphics/rastport.h"
  15. #include "hardware/blit.h"
  16. #include "hardware/custom.h"
  17.  
  18. /*---------------------------------------------------------------------------
  19.  * define some stuff for blitter operations 
  20.  *--------------------------------------------------------------------------*/
  21. typedef struct
  22. {
  23.     UBYTE *blt_apt, *blt_bpt, *blt_cpt, *blt_dpt;
  24.     UWORD blt_amod, blt_bmod, blt_cmod, blt_dmod;   /* offset in bytes */
  25.  
  26.     UWORD blt_afwm, blt_alwm;             /* first and last word masks */
  27.     UWORD blt_con0;                    /* control register 0 */
  28.     UWORD blt_con1;                    /* control register 1 */
  29.  
  30.     UWORD blt_size;                    /* # of WORDS to move */
  31. } bltnode;
  32.  
  33. /* define the minterm for a blit thru a mask */
  34. /* regA is the src data, regB is the mask, regC = regD = the destination */
  35. #define COOKIE_CUT    0xe2
  36. #define CUSTOM_HW_BASE    0xdff000
  37.  
  38. extern struct Custom custom;        /* define the custom chips address */
  39.  
  40. /* struct Custom *chips = &custom; */    /* originally this way, failed under LC4 */
  41.  
  42. /* I hate to hard-code this, but it worked... */
  43.  
  44. struct Custom *chips = (struct Custom *) CUSTOM_HW_BASE;
  45.  
  46. bltnode blit;
  47.  
  48. /*---------------------------------------------------------------------------
  49.  * BlitBitMapMask() -- blit a bitmap thru a mask to another bitmap
  50.  *        both BitMap's must be the same size
  51.  *--------------------------------------------------------------------------*/
  52. void    BlitBitMapMask( src, dst, mask )
  53. struct BitMap *src,*dst;
  54. UBYTE *mask;
  55. {
  56.     extern     void    DoBlit ();
  57.  
  58.     register UBYTE **src_plane;
  59.     register UBYTE **dst_plane;
  60.     register int i;
  61.  
  62.     /* initialize the blitter control structure */
  63.     blit.blt_afwm = 0xffff;
  64.     blit.blt_alwm = 0xffff;
  65.  
  66.     blit.blt_bpt = mask;            /* reg B is the mask plane */
  67.     blit.blt_amod = 0;            /* no modulos */
  68.     blit.blt_bmod = 0;
  69.     blit.blt_cmod = 0;
  70.     blit.blt_dmod = 0;
  71.  
  72.     blit.blt_con1 = 0;            /* control register 1 */
  73.     blit.blt_con0 = DEST | SRCC |SRCB | SRCA | COOKIE_CUT;
  74.  
  75.     /* set the size register from the bit map height and width */
  76.     blit.blt_size = ( ((src->Rows & VSIZEMASK) << 6 ) |
  77.               ((src->BytesPerRow >> 1) & HSIZEMASK) );
  78.  
  79.     src_plane = &src->Planes[0];
  80.     dst_plane = &dst->Planes[0];
  81.     for( i = src->Depth; i--; )
  82.     {
  83.         blit.blt_apt = *src_plane;
  84.         blit.blt_cpt = *dst_plane;
  85.         blit.blt_dpt = *dst_plane;
  86.         DoBlit( &blit );
  87.         src_plane++;
  88.         dst_plane++;
  89.     }
  90. }
  91.  
  92. /*---------------------------------------------------------------------------
  93.  * DoBlit() -- do one blitter operation
  94.  *--------------------------------------------------------------------------*/
  95. void    DoBlit( blt )
  96. register bltnode *blt;            /* the control struct for blitter operation */
  97. {
  98.     register struct Custom *cp;    /* the custom chips address */
  99.  
  100.     cp = chips;
  101.  
  102.     OwnBlitter();
  103.  
  104.     /* set the blitter data address's */
  105.     cp->bltapt   = (APTR)blt->blt_apt;
  106.     cp->bltbpt   = (APTR)blt->blt_bpt;
  107.     cp->bltcpt   = (APTR)blt->blt_cpt;
  108.     cp->bltdpt   = (APTR)blt->blt_dpt;
  109.  
  110.     /* set the blitter modulo values */
  111.     cp->bltamod  = blt->blt_amod;
  112.     cp->bltbmod  = blt->blt_bmod;
  113.     cp->bltcmod  = blt->blt_cmod;
  114.     cp->bltdmod  = blt->blt_dmod;
  115.  
  116.     /* set the first and last word mask values */
  117.     cp->bltafwm  = blt->blt_afwm;
  118.     cp->bltalwm  = blt->blt_alwm;
  119.  
  120.     /* set control registers */
  121.     cp->bltcon0  = blt->blt_con0;
  122.     cp->bltcon1  = blt->blt_con1;
  123.  
  124.     cp->bltsize  = blt->blt_size;   /* go for it !!! */
  125.  
  126.     WaitBlit();
  127.     DisownBlitter();
  128. }
  129.  
  130.